package org.androidpush.ui;

import java.security.MessageDigest;


/**
 * 采用MD5加密解密
 * @author tfq
 * @datetime 2011-10-13
 */
public class MD5Util {

    /***
     * MD5加密
     */
    public static String MD5Encryption(String strEncryption){
        MessageDigest md = null;
        try{
            md = MessageDigest.getInstance("MD5");
        }catch (Exception e){
            System.out.println(e.toString());
            e.printStackTrace();
            return "";
        }
        byte[] Md5byte = md.digest(strEncryption.getBytes());
        return getString(Md5byte);
    }

    private static String getString(byte[] b){
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < b.length; i ++){
            sb.append(b[i]);
        }
        return sb.toString();
    }

    /**
     * 加密解密算法 执行一次加密，两次解密
     */
    public static String ConvertEncryption(String strEncryption){

        char[] a = strEncryption.toCharArray();
        for (int i = 0; i < a.length; i++){
            a[i] = (char) (a[i] ^ 'g');
        }
        String result = new String(a);
        return result;
    }
}
